﻿using System;

namespace BuddHa.Common.SMUtil
{
    using Implementation.V1;
    using Implementation.V2;
    using Pool;
    public class SMBuild
    {
        public static ISM2Dispatch BuildSMDispatch(string userId, string publicKey = "", string privateKey = "", SMVersions verson = SMVersions.V1, SMInEncodingTypes encodingType = SMInEncodingTypes.Hex)
        {
            if (string.IsNullOrEmpty(privateKey) && string.IsNullOrEmpty(publicKey))
            {
                throw new Exception("生成SMDispatch失败,公钥与私钥不能同时为空");
            }
            switch (verson)
            {
                case SMVersions.V2:
                    return new SM2V2Dispatch(publicKey, privateKey, userId, encodingType);
                case SMVersions.V1:
                default:
                    return new SMV1Dispatch(userId, privateKey, publicKey, encodingType);
            }

        }

        public static ISM2Key CreateKey(SMVersions verson = SMVersions.V1, SMInEncodingTypes encodingType = SMInEncodingTypes.Hex)
        {
            switch (verson)
            {
                case SMVersions.V2:
                    return SM2V2Dispatch.CreateKey(encodingType);
                case SMVersions.V1:
                default:
                    return SMV1Dispatch.CreateKey();
            }
        }


        public static ISM2PoolDispatch CreateSMPoolDispatch(IModelPoolOption modelPoolOption, string userId, string publicKey = "", string privateKey = "", SMVersions verson = SMVersions.V1, SMInEncodingTypes encodingType = SMInEncodingTypes.Hex)
        {
            switch (verson)
            {
                case SMVersions.V1:
                    return new SM2V1PoolDispatch(modelPoolOption, userId, publicKey, privateKey, encodingType);
                case SMVersions.V2:
                default:
                    return new SM2V2PoolDispatch(modelPoolOption, publicKey, privateKey, userId, encodingType);
            }
        }
    }
}
